<html>
<!--
  ~ Copyright 2024 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->
<head>
</head>
<body>
<noscript><p><strong>JavaScript was not enabled. Sound will not generate.</strong></p></noscript>
<input id="play" type="checkbox" onchange="soundToggled()" checked><label>Generate tone in web content</label>
<p>
    This web content will immediately generate a continuous 440Hz tone at 50% volume (without first
    needing user interaction). Check device volume settings as appropriate.
</p>
<p>
    By default, the WebView loading this page will be muted, so a tone should not be heard until it
    is unmuted.
</p>
<script defer type="text/javascript">
    const play = document.getElementById("play");
    const audioCtx = new window.AudioContext;
    const gain = audioCtx.createGain();
    gain.connect(audioCtx.destination);
    let oscillator = null;

    function soundToggled() {
        if (play.checked) {
            oscillator = audioCtx.createOscillator();
            oscillator.type = 'sine';
            oscillator.frequency.setValueAtTime(440, audioCtx.currentTime);
            gain.gain.setValueAtTime(0.5, audioCtx.currentTime);
            oscillator.connect(gain);
            oscillator.start();
        } else {
            if (oscillator) {
                oscillator.stop();
                oscillator = null;
            }
        }
    }

    soundToggled();
</script>
</body>
</html>